package com.feituan.manager.controller;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.feituan.core.persistence.service.IRechargeRecordService;
import com.feituan.core.pojo.entity.RechargeRecord;
import com.feituan.core.pojo.request.RechargeRecordReq;
import com.feituan.core.pojo.response.Response;
import com.feituan.core.pojo.response.page.PageData;
import lombok.Data;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 充值记录
 */
@RestController
@RequestMapping("/rechargeRecord")
public class RechargeRecordController {

    @Resource
    private IRechargeRecordService rechargeRecordService;


    /**
     * 新增余额充值记录
     * @param rechargeRecord rechargeRecord
     * @return
     */
    @PostMapping("/submit")
    public Response<Long> save(RechargeRecord rechargeRecord) {
        return Response.success(rechargeRecordService.saveRecord(rechargeRecord));
    }


    @PostMapping("/select_page")
    public PageData<RechargeRecord> selectList(RechargeRecordReq rechargeRecord) {
        Page<RechargeRecord> page = new Page<>();
        page.setCurrent(rechargeRecord.getPage());
        page.setSize(rechargeRecord.getLimit());
        LambdaQueryWrapper<RechargeRecord> qw = new LambdaQueryWrapper<>();
        qw.eq(rechargeRecord.getUserId() != null, RechargeRecord::getUserId, rechargeRecord.getUserId());
        qw.eq(rechargeRecord.getStatus() != null, RechargeRecord::getStatus, rechargeRecord.getStatus());
        Page<RechargeRecord> rechargeRecordPage = this.rechargeRecordService.getBaseMapper().selectPage(page, qw);
        return PageData.build(rechargeRecordPage.getCurrent(), rechargeRecordPage.getTotal(), rechargeRecordPage.getRecords());
    }


}
